package com.weixiao.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

//TTL队列 配置文件类代码
@Configuration
public class TtlQueueConfig {
    //普通交换机的名称
    private static final String EXCHANGE = "exchange";
    //普通队列的名称
    private static final String QUEUE = "Q";

    //声明Exchange
    @Bean
    public DirectExchange Exchange() {
        return new DirectExchange(EXCHANGE);
    }

    //声明普通队列 TTL设置为10s
    @Bean
    public Queue Queue() {
        Map<String, Object> map = new HashMap<>();
        return QueueBuilder.durable(QUEUE).build();
    }

    //绑定队列跟交换机
    @Bean
    public Binding QueueBindingExchange(Queue Queue,DirectExchange Exchange) {
        return BindingBuilder.bind(Queue).to(Exchange).with("X");
    }
}